<template>
    <div>
        <div class="bjtk xglxr_box">
            <div class="bjtk_list">
                <div class="head">
                    <a-button @click="back"> 
                        返回
                    </a-button>
                    <a-button class="editable-add-btn" @click="close">
                        <a-icon type="close"/>
                    </a-button>
                </div>
                <div class="bj">
                    <div class="list">
                        <span style="color:red;width:5px;display:inline-block;">*</span><span>姓名：</span>
                        <a-input class="gjxq_area" placeholder="请输入姓名" v-model="xglxr_xm" allow-clear @change="onXgxmChange" />
                    </div>
                    <div class="list">
                        <span style="color:red;width:5px;display:inline-block;">*</span><span>手机：</span>
                        <a-input class="gjxq_area" placeholder="请输入手机" v-model="xglxr_phone" allow-clear @change="onXgphoneChange" />
                    </div>
                    <div class="list">
                        <span style="color:red;width:5px;display:inline-block;">*</span><span>电话：</span>
                        <a-input class="gjxq_area" placeholder="请输入电话" v-model="xglxr_lxdh" allow-clear @change="onXglxdhChange" />
                    </div>
                    <div class="list_btn">
                        <a-button type="primary" style="width: 130px" @click="SvaeLxr()"  >保存联系人</a-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import qs from "qs";
import moment from 'moment';
export default {
   
    data(){
        return{
            moment,
            // 跳转携带参数信息
            xsdinfo:'',
            // 销售单号
            xsdh:'',
            // 单位名称
            dwmc:'',
            // 公司编码
            gsbm:'',
            // 授权id
            sqdwid:'',
            //数据库名称
            database:'ERP2_BEARING',
            // ip地址
            ip:'122.112.240.180',
            // 姓名
            // 当前联系人信息
            lxrInfo:'',
            xglxr_xm:'',
            // 手机号
            xglxr_phone:'',
            // 电话
            xglxr_lxdh:'',
            // 当前行信息
            genjinInfo:'',
            // edit
            edit:'1',

        }
    },

    methods:{
         // 返回上一级
        back(){
            this.$store.state.xgtj = false;
            this.$store.state.jsgl = true;
        },
        //关闭弹出框
        close() {
            this.$store.state.xgtj = false;
        },
        // 姓名修改
        onXgxmChange(e){
            this.xglxr_xm=e.target.value;
        },
        // 手机号修改
        onXgphoneChange(e){
            this.xglxr_phone=e.target.value;
        },
         // 电话修改
        onXglxdhChange(e){
            this.xglxr_lxdh=e.target.value;
        },
        // 保存联系人
        SvaeLxr(){
            if(this.xglxr_xm!='' && this.xglxr_xm!=undefined){
                if(this.edit==0){
                    this.axios
                    .post(
                        "https://yb.bearing.cn/wxapi/smt_newLxrEdit.php",
                        qs.stringify({
                            gsbm: this.gsbm,
                            dwmc: this.dwmc,
                            lxr: this.xglxr_xm,
                            lxdh: this.xglxr_lxdh,
                            phone: this.xglxr_phone,
                            database: this.database,
                            IP:this.ip,
                            vison:this.vison,
                        })
                    ).then(res=>{
                        console.log(res);
                    })
                }else{
                    this.axios
                    .post(
                        "https://yb.bearing.cn/wxapi/smt_newLxrEdit.php",
                        qs.stringify({
                            id_num:this.id_num,
                            gsbm: this.gsbm,
                            dwmc: this.dwmc,
                            lxr: this.xglxr_xm,
                            lxdh: this.xglxr_lxdh,
                            phone: this.xglxr_phone,
                            database: this.database,
                            IP:this.ip,
                            vison:this.vison,
                        })
                    ).then(res=>{
                        if(res.data.code==103){
                            this.$message.success('修改成功');
                            this.$store.state.xgtj = false;
                            this.$store.state.jsgl = true;
                        }
                    })
                }
            }
         
            
        }
    },
    created(){
        this.gsbm=sessionStorage.getItem("gsbm");
        this.genjinInfo=JSON.parse(sessionStorage.getItem("genjinInfo"));
        this.dwmc=this.genjinInfo.DWMC;
        console.log( this.$store.state.lxrList);
        console.log( this.$store.state.lxr_i);
        this.lxrInfo= this.$store.state.lxrList[this.$store.state.lxr_i]
        console.log(this.lxrInfo);
        this.xglxr_xm=this.lxrInfo.lxr
        this.xglxr_phone=this.lxrInfo.phone
        this.xglxr_lxdh=this.lxrInfo.lxdh
        this.id_num=this.lxrInfo.ID_NUM;
    }
}
</script>

<style lang='less' >
    .bjtk {
        // position: absolute;
        // z-index: 9999;
        // width: 45%;
        // height: auto;
        // background-color: #fff;
        // text-align: center;
        // padding: 20px;
        // top: 160px;
        // left: 50%;
        // transform: translateX(-50%);

        .bjtk_list {
            .head {
                display: flex;
                justify-content: space-between;
            }

            .bj {
                .ts{
                    margin:5px 0 0 75px;
                    color:red;
                    font-size: 12px;
                    i{
                        margin: 0 5px;
                    }
                }
                .list {
                    margin: 20px 0;
                    display: flex;
                    justify-content: space-around;
                    .cz_btn{
                        display: block;
                        width: 25%;
                    }
                    .tit {
                        display: inline-block;
                        width: 80px;
                        text-align: right;

                        i {
                            color: #ff0000;
                            padding: 0 4px;
                        }
                    }

                    .radio {
                        margin-left: 10px;
                    }

                    .text {
                        width: 288px;
                        vertical-align: top;
                    }


                }
                .bcloading{
                    position: relative;
                    left: 42%;
                    bottom: 214px;
                }
                .list_btn {
                    text-align: center;

                    button {
                        width: 200px;
                        height: 40px;
                    }
                }
            }
        }
    }
</style>
